package com.atguigu.controller;

import com.atguigu.entity.UserInfo;
import com.atguigu.result.Result;
import com.atguigu.service.UserFollowService;
import com.atguigu.vo.UserFollowVo;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @title：
 * @author：Yu
 * @create：2023-02-25 10:44
 * @description：
 */
@RequestMapping("/userFollow")
@ResponseBody
@Controller
public class userFollowController {
    @DubboReference
    private UserFollowService userFollowService;

    @RequestMapping("/auth/follow/{houseId}")
    public Result follow(@PathVariable Long houseId, HttpSession session) {
        //1.获取当前登录人信息
        UserInfo userInfo = (UserInfo) session.getAttribute("userInfo");
        //2.添加数据至userFollow表
        userFollowService.follow(houseId, userInfo.getId());
        return Result.ok();
    }

    @RequestMapping("/auth/list/{pageNum}/{pageSize}")
    public Result lists(@PathVariable Integer pageNum, @PathVariable Integer pageSize, HttpSession session) {
        //1.获取登录人信息
        UserInfo userInfo = (UserInfo) session.getAttribute("userInfo");
        //2.调用数据库获取分页信息
        PageInfo<UserFollowVo> page = userFollowService.findList(pageNum, pageSize, userInfo.getId());
        return Result.ok(page);
    }

    @RequestMapping("/auth/cancelFollow/{userFollowId}")
    public Result deleted(@PathVariable Long userFollowId) {
        userFollowService.delete(userFollowId);
        return Result.ok();
    }
}
